home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2535 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.2 KB  |  52 lines

  1. Newsgroups: comp.lang.c++
  2. Path: netcom.com!marnold
  3. From: marnold@netcom.com (Matt Arnold)
  4. Subject: Re: forward referencing in Borland 4.52
  5. Message-ID: <marnoldDLD9nC.18w@netcom.com>
  6. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  7. References: <4dkfk2$e4v@cloner3.netcom.com>
  8. Date: Thu, 18 Jan 1996 07:47:36 GMT
  9. Sender: marnold@netcom9.netcom.com
  10.  
  11. regmia@ix.netcom.com writes:
  12.  
  13.  
  14.  
  15. >Does anyone know how to CORRECTLY create a forward reference to
  16. >class.
  17.  
  18. >For those of you who may not understand what I am referring to:
  19.  
  20. >Forward referencing of a class means to declare a variable of a class
  21. >type and be able to use that variable BEFORE the class is actually
  22. >defined.
  23.  
  24. A follow up to my previous post...  The original poster should note
  25. that forward referencing only allows one to DECLARE variables of the 
  26. forward-referenced class (and you are also limited to pointer and
  27. references variables at that!).  You can not "use" those variables 
  28. (call members, etc.) until the compiler has seen the class declaration 
  29. as normal.  
  30.  
  31. You assumption about what forward referencing above allows is only 
  32. half correct.  Think about it, if the compiler has not seen a 
  33. declaration of the class in question, there is no way it can parse 
  34. code refering to members of that class!  But, there is no trouble 
  35. parsing code that declares pointers/references to the unseen class 
  36. since the size (for one thing) of the storage for such variables are 
  37. already known to the compiler.  This is all that forward-referencing 
  38. gives you---the ability to declare pointers and references to an as-
  39. yet-unseen class.
  40.  
  41. Anyway, the limitations of forward referencing should not come as a 
  42. surprise---C works is a similar way when you forward-declare structs.
  43.  
  44. Regards,
  45. -------------------------------------------------------------------------
  46. Matt Arnold                       |        | ||| | |||| |  | | || ||
  47. marnold@netcom.com                |        | ||| | |||| |  | | || ||
  48. Boston, MA                        |      0 | ||| | |||| |  | | || ||
  49. 617.389.7384 (h) 617.576.2760 (w) |        | ||| | |||| |  | | || ||
  50. C++, MIDI, Win32/95 developer     |        | ||| 4 3 1   0 8 3 || ||
  51. -------------------------------------------------------------------------
  52.